Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilizing "multi shot" ability of trees #38

Closed
wants to merge 3 commits into from

Conversation

joshc-slac
Copy link
Collaborator

@joshc-slac joshc-slac commented Sep 4, 2024

Description

Motivation and Context

Half the whole point of sequence automation is to actively manage the state of our configured devices such that should they transition to an undesired state they can automatically transition back along defined transition vectors. Up until this point all the work packaged in ActionNodes only ran once, this will keep it living with the life cycle of the program such that when the tree is traversed again and a CheckAndDo node notices a state is out of whack it can fire off the action to deal with it again!

Details

FEAT:

Not multi shot:

BEAMS/beams/tree_config.py

Lines 169 to 179 in a2c883f

def get_tree(self) -> ActionNode:
def work_func(myself,
comp_condition: Callable[[Any], bool],
volatile_status: VolatileStatus,
wait_for_tick: Event()):
py_trees.console.logdebug(f"WAITING FOR INIT {os.getpid()} "
f"from node: {self.name}")
wait_for_tick.wait()
# While termination_check is not True
while not comp_condition(): # TODO check work_gate.is_set()

Multi shot!:

BEAMS/beams/tree_config.py

Lines 169 to 180 in fb2f291

def get_tree(self) -> ActionNode:
def work_func(myself,
comp_condition: Callable[[Any], bool],
volatile_status: VolatileStatus,
wait_for_tick: Event()):
while myself.do_work.value:
py_trees.console.logdebug(f"WAITING FOR INIT {os.getpid()} "
f"from node: {self.name}")
wait_for_tick.wait()
# While termination_check is not True
while not comp_condition(): # TODO check work_gate.is_set()

this works because atexit registers the Worker classes stop_work function during the setup call of the ActionNode:

# Having this in setup means the workthread should always be running.
self.worker.start_work()
atexit.register(
self.worker.stop_work
) # TODO(josh): make sure this cleans up resources when it dies

MNT:

Taking advantage of PR #34 which concertized all work this library packages in the Worker class, for ActionNodes augmented by the derived class ActionWorker.

This PR does a little maintenance nitty gritty of cleaning up moving the inter-proccess communication variables to being owned by the ActionNode class as opposed to being defined in the work function which I am considering "super user space".

Before:

self.work_gate = work_gate
self.lock = work_lock
self.worker = ActionWorker(proc_name=name,
volatile_status=self.__volatile_status__,
work_func=work_func,
comp_cond=completion_condition,
stop_func=None
) # TODO: some standard notion of stop function could be valuable

Now:

# Interprocess signalling mechanisms
self.__volatile_status__ = VolatileStatus(self.status) # Shares BT Status by wrapping Value
self.work_gate = Event() # Mechanism to avoid busy wait / signal node has been py_trees "initialized"
self.worker = ActionWorker(proc_name=name,
volatile_status=self.__volatile_status__,
wait_for_tick=self.work_gate,
work_func=work_func,
comp_cond=completion_condition,
stop_func=None
) # TODO: some standard notion of stop function could be valuable

This requires that we slightly change the signature of our work functions such that they can take this Event() object defined in the ActionNode class1 and that ActionWorker pass the Event as an additional argument to the add_arg field of Worker. Convenient that we decided to wrap Worker this way... extensible.. josh pats himself on the back.

How Has This Been Tested?

Where Has This Been Documented?

Pre-merge checklist

  • Code works interactively
  • Code follows the style guide
  • Code contains descriptive docstrings, including context and API
  • New/changed functions and methods are covered in the test suite where possible
  • Test suite passes locally
  • Test suite passes on GitHub Actions
  • Ran docs/pre-release-notes.sh and created a pre-release documentation page
  • Pre-release docs include context, functional descriptions, and contributors as appropriate

Footnotes

  1. I really want to take advantage of wrappers / functools / inspect to very nicely package the work that gets serialized / specified in tree_config. Have said before but 80% of user needs should be met with jsonic config files. I would like the remaining 20% to be able to very easily / neatly write their own functions I think thats a 10x increase in the capability of this library. I still want to obfuscate IPC concerns from those 20%, I feel like checking that ActionWorker work funcs are correctly defined (signature-ed minimally). I think ENH: Make sure errors in child process bubble up #35 is also very related.

@joshc-slac joshc-slac requested a review from tangkong September 4, 2024 02:28
@joshc-slac
Copy link
Collaborator Author

Will mark ready for review when I actually get the tests in

@joshc-slac
Copy link
Collaborator Author

closed by #41

@joshc-slac joshc-slac closed this Sep 11, 2024
@joshc-slac joshc-slac deleted the joshc-slac/multishot-utilizer branch September 11, 2024 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Take advantage of multi shot trees
1 participant